#include <stdio.h>
#include <stdlib.h>

#include "queue.h"

struct SLIST_ITEM {
    int value;
    SLIST_ENTRY(SLIST_ITEM) entry;
};

static SLIST_HEAD(,SLIST_ITEM) slist_head;
//static SLIST_HEAD(,SLIST_ITEM) slist_head = SLIST_HEAD_INITIALIZER();

int main(int argc, char *argv[])
{
    int i = 0;
    struct SLIST_ITEM *item;
    struct SLIST_ITEM *tmp_item;

    SLIST_INIT(&slist_head);

    if (SLIST_EMPTY(&slist_head))
        printf("single list is empty\n");

    for( i = 0; i < 10; i += 1)
    {
        item = (struct SLIST_ITEM *)malloc(sizeof(struct SLIST_ITEM));
        item->value = i;
        SLIST_INSERT_HEAD(&slist_head, item, entry);
    }

    printf("after insert 10 item to single list:\n");
    SLIST_FOREACH(item, &slist_head, entry)
        printf("item value = %d\n", item->value);

    SLIST_FOREACH(tmp_item, &slist_head, entry)
    {
        if(tmp_item->value % 2 != 0)
            SLIST_REMOVE(&slist_head, tmp_item, SLIST_ITEM, entry);
    }

    printf("after delete items from single list:\n");
    SLIST_FOREACH(item, &slist_head, entry)
        printf("item value = %d\n", item->value);

    /* item->value = 9, has been removed, so this will dump */
    SLIST_REMOVE(&slist_head, tmp_item, SLIST_ITEM, entry);

    return 0;
}
